﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace peonwar
{
    static class CampaignManager
    {
        public static List<Node> Path;
        public static int ActualMission;
        public static Sprite Selector;

        public static void Initialize()
        {
            Path = new List<Node> { };
            Path.Add(new Node(new Vector2(540, 520), null, 1));
            Path.Add(new Node(new Vector2(580, 380), null, 2));
            Path.Add(new Node(new Vector2(640, 300), null, 3));
            Path.Add(new Node(new Vector2(650, 220), null, 4));
            Path.Add(new Node(new Vector2(575, 164), null, 5));
            Path.Add(new Node(new Vector2(708, 160), null, 6));
            Path.Add(new Node(new Vector2(810, 200), null, 7));
            Path.Add(new Node(new Vector2(840, 310), null, 8));
            Path.Add(new Node(new Vector2(987, 350), null, 9));
            Path.Add(new Node(new Vector2(1085, 275), null, 10));
            Path.Add(new Node(new Vector2(1117, 188), null, 11));
            Path.Add(new Node(new Vector2(1150, 115), null, 12));

            ActualMission = Math.Min(SettingManager.CurrentProfil.Progress, 12);
            Selector = new Sprite(Path[ActualMission - 1].Position);
            Selector.Texture = GameTexture.CampaignItems[2];
            UpdateNodes();
        }

        public static void Update(MouseState mouse)
        {
            for (int i = 0; i < Math.Min(SettingManager.CurrentProfil.Progress, 12); i++)
            {
                if (Path[i].IsPressed(mouse))
                {
                    Selector.Position = Path[i].Position;
                    ActualMission = i + 1;
                    return;
                }
            }
        }

        public static void UpdateNodes()
        {
            for (int i = 0; i < Path.Count(); i++)
            {
                if (i < SettingManager.CurrentProfil.Progress)
                    Path[i].Texture = GameTexture.CampaignItems[1];
            }
            if (SettingManager.CurrentProfil.Progress < 13)
                Path[SettingManager.CurrentProfil.Progress - 1].Texture = GameTexture.CampaignItems[0];
            else
                Path[11].Texture = GameTexture.CampaignItems[1];
            Selector.Position = Path[Math.Min(SettingManager.CurrentProfil.Progress, 12) - 1].Position;
            ActualMission = Math.Min(SettingManager.CurrentProfil.Progress, 12);
        }

        public static void Draw(SpriteBatch spriteBatch)
        {
            for (int i = 0; i < Math.Min(SettingManager.CurrentProfil.Progress, 12); i++)
            {
                Path[i].Draw(spriteBatch);
            }

            Selector.Draw(spriteBatch, null);
        }
    }
}
